package com.haifeng.mywriteaidldemo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import androidx.annotation.Nullable;

import com.haifeng.mywriteaidldemo.MyAIDL.MyInterface;
import com.haifeng.mywriteaidldemo.MyAIDL.Proxy;
import com.haifeng.mywriteaidldemo.MyAIDL.Stub;

/***
 * 远程service
 */
public class MyService extends Service {
    String[] names = new String[50];
    int index = 0;
    int left = 50;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        System.out.println(" the service is started");

        return interfacs;
    }

    Stub interfacs = new Stub() {
        @Override
        public void addname(String position) throws RuntimeException {

            names[index] = position;
            index++;
            left--;
            System.out.println("add a name into zhe names,is " + position + ",the names can input " + left + " name");

        }

        @Override
        public String getname(String key) throws RuntimeException {

            int position = Integer.parseInt(key);
            System.out.println("zhe  " + key + " name is" + names[position]);


            return names[position];
        }
    };
}
